package Easy;

public class LC0724 {
    public int pivotIndex(int[] nums) {
        int length = nums.length;
        int[] prefixSum = new int[length], postfixSum = new int[length];
        for (int i = 1; i < length; i++) {
            prefixSum[i] = prefixSum[i - 1] + nums[i - 1];
            postfixSum[length - 1 - i] = postfixSum[length - i] + nums[length - i];
        }
        for (int i = 0; i < length; i++) {
            if (prefixSum[i] == postfixSum[i]) return i;
        }

        return -1;
    }
}
